package com.rxjava.http;

import rx.Observable;
import rx.Subscriber;

/**
 * Created by kkmike999 on 16/3/21.
 */
public class UserHttp implements IUserHttp {

    @Override
    public Observable<String> loadUserFromServer() {
        return rx.Observable.create(new Observable.OnSubscribe<String>() {

            public void call(final Subscriber<? super String> subscriber) {
                boolean isError = false;

                if (isError) {
                    subscriber.onError(new Throwable("404"));
                } else {
                    String string = "{ \"uid\":1, \"name\":\"小明\"}";// 服务器返回

                    subscriber.onNext(string);
                    subscriber.onCompleted();
                }
            }
        });
    }
}
